//=============================================================================
#include "CApp.h"

//=============================================================================
CApp* CApp::Instance = NULL;

//=============================================================================
CApp::CApp() {
    Running = true;

    Instance = this;
}

//-----------------------------------------------------------------------------
int CApp::OnExecute() {
    if(OnInit() == false) return -1;

    SDL_Event Event;

    while(Running) {
        while(FE_PollEvent(&Event)) {
            OnEvent(&Event);
        }

        OnLoop();

        SDL_Delay(0);
    }

    OnCleanup();

    return 0;
}

//-----------------------------------------------------------------------------
BOOL WINAPI CApp::ConsoleHandler(DWORD CEvent) {
    switch(CEvent) {
        case CTRL_C_EVENT:
        case CTRL_BREAK_EVENT:
        case CTRL_CLOSE_EVENT:
        case CTRL_LOGOFF_EVENT:
        case CTRL_SHUTDOWN_EVENT: {
            if(CApp::Instance) {
                CApp::Instance->Running = false;
            }

            break;
        }
    }

    return false;
}

//=============================================================================
int main(int argc, char *argv[]) {
    CApp theApp;

    return theApp.OnExecute();
}

//=============================================================================
